//
//  ModuleDetailCell.m
//  Project
//
//  Created by 冯东辉 on 2018/9/21.
//  Copyright © 2018年 FengDongHui. All rights reserved.
//

#import "ModuleDetailCell.h"

@implementation ModuleDetailCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self initSubViews];
    }
    
    return self;
}

- (void)initSubViews {
    
    _city_name_l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 40)];
    _city_name_l.textColor = UICOLOR_HEX(0xff000000);
    _city_name_l.textAlignment = NSTextAlignmentRight;
    _city_name_l.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_city_name_l];
    
    _ind_data_l = [[UILabel alloc] initWithFrame:CGRectMake(GET_SCREEN_WIDTH()-30-_city_name_l.width-10, 0, _city_name_l.width, _city_name_l.height)];
    _ind_data_l.textColor = UICOLOR_HEX(0xff000000);
    _ind_data_l.textAlignment = NSTextAlignmentRight;
    _ind_data_l.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_ind_data_l];
    
    _base_progess_view = [[UIView alloc] initWithFrame:CGRectMake(_city_name_l.right+5, (40-10)/2.0f, GET_SCREEN_WIDTH()-30-_city_name_l.width*2-10-10, 10)];
    _base_progess_view.backgroundColor = UICOLOR_HEX(0xffe9e9e9);
    _base_progess_view.layer.cornerRadius = 5;
    _base_progess_view.layer.masksToBounds = YES;
    [self.contentView addSubview:_base_progess_view];
    
    _progess_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, GET_SCREEN_WIDTH()-30-_city_name_l.width*2-10-10, 10)];
    [_base_progess_view addSubview:_progess_view];
}

- (void)reloadSubViewWithData:(NSArray *)data indexPath:(NSIndexPath *)indexPath maxNum:(CGFloat)maxNum {
    
    NSDictionary *dic = data[indexPath.row];
    
    _city_name_l.text = [NSString stringWithFormat:@"%@.%@", dic[@"topnum"], dic[@"citY_NAME"]];
    
    NSString *inD_DATA = [NSString stringWithFormat:@"%@", dic[@"inD_DATA"]];
    if ([ProjectTools isValiString:inD_DATA]) {
        inD_DATA = @"0.00";
    }
    
    CGFloat indData = [inD_DATA floatValue];
    
    _ind_data_l.text = [NSString stringWithFormat:@"%.2f", indData];
    
    NSInteger isColor = [dic[@"iscolor"] integerValue];
    
    CGFloat progress = 1;
    
    if (maxNum != 0) {
        progress = indData/maxNum;
    }
    
    _progess_view.frame = CGRectMake(0, 0, _base_progess_view.width * progress, _base_progess_view.height);
    
    for (CALayer *layer in _progess_view.layer.sublayers) {
        
        [layer removeFromSuperlayer];
    }
    
    if (isColor == 0) {
        
        [_progess_view.layer addSublayer:[ProjectTools setJianBianWithBenginColor:UICOLOR_HEX(0xff94d0fb) endColor:UICOLOR_HEX(0xff1098fa) frame:_progess_view.bounds cornerRadius:0]];
        
    }else {
        
        [_progess_view.layer addSublayer:[ProjectTools setJianBianWithBenginColor:UICOLOR_HEX(0xfff7b9b9) endColor:UICOLOR_HEX(0xffdd4d4d) frame:_progess_view.bounds cornerRadius:0]];
    }
}


@end
